#include "LineTest.h"

using physicsworks::math::Vec3;
using physicsworks::math::equal;

CPPUNIT_TEST_SUITE_REGISTRATION(LineTest);

void LineTest::setUp()
{
	l0f = new Line<float>(Vec3<float>(5, 3, 6), Vec3<float>(-1, 5, 0));
	l0d = new Line<double>(Vec3<double>(5, 3, 6), Vec3<double>(-1, 5, 0));
	
	p0f = new Plane<float>(Vec3<float>(2, 3, 1), Vec3<float>(3, 2, 1), Vec3<float>(5, 5, 1));
	p0d = new Plane<double>(Vec3<double>(2, 3, 1), Vec3<double>(3, 2, 1), Vec3<double>(5, 5, 1));
	
	p1f = new Plane<float>(Vec3<float>(0, 2, 3), Vec3<float>(0, -2, -1), Vec3<float>(8, 0, 1));
	p1d = new Plane<double>(Vec3<double>(0, 2, 3), Vec3<double>(0, -2, -1), Vec3<double>(8, 0, 1));
}

void LineTest::testGeneration()
{
	CPPUNIT_ASSERT(equal<float>(l0f->getDirection().x, -6/std::sqrt(76)));
	CPPUNIT_ASSERT(equal<float>(l0f->getDirection().y,  2/std::sqrt(76)));
	CPPUNIT_ASSERT(equal<float>(l0f->getDirection().z, -6/std::sqrt(76)));
	
	CPPUNIT_ASSERT(equal<double>(l0d->getDirection().x, -6/std::sqrt(76)));
	CPPUNIT_ASSERT(equal<double>(l0d->getDirection().y,  2/std::sqrt(76)));
	CPPUNIT_ASSERT(equal<double>(l0d->getDirection().z, -6/std::sqrt(76)));
	
	Line<float> lf(*p0f, *p1f);
	Line<double> ld(*p0d, *p1d);
	
	CPPUNIT_ASSERT(equal<float>(lf.getDirection().x, 1));
	CPPUNIT_ASSERT(equal<float>(lf.getDirection().y, 0));
	CPPUNIT_ASSERT(equal<float>(lf.getDirection().z, 0));
	// the lf.getPoint().x can be any value
	CPPUNIT_ASSERT(equal<float>(lf.getPoint().y, 0));
	CPPUNIT_ASSERT(equal<float>(lf.getPoint().z, 1));
	
	CPPUNIT_ASSERT(equal<double>(ld.getDirection().x, 1));
	CPPUNIT_ASSERT(equal<double>(ld.getDirection().y, 0));
	CPPUNIT_ASSERT(equal<double>(ld.getDirection().z, 0));
	// the ld.getPoint().x can be any value
	CPPUNIT_ASSERT(equal<double>(ld.getPoint().y, 0));
	CPPUNIT_ASSERT(equal<double>(ld.getPoint().z, 1));
}

void LineTest::tearDown()
{
	delete l0f;
	delete l0d;
	
	delete p0f;
	delete p1f;
	delete p0d;
	delete p1d;
	
}
